package com.quick.mq.impl;

import com.quick.common.Component.ExchangeType;
import com.quick.common.service.IMQService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MQService implements IMQService {
    @Autowired
    RabbitTemplate rabbitTemplate;
    private static final String DEFAULT_EXCHANGE = "topicExchange";
    private static final String DEFAULT_ROUTING_KEY = "qc.order";

    @Override
    public void sendMessage(String message) {
        rabbitTemplate.convertAndSend(DEFAULT_EXCHANGE, DEFAULT_ROUTING_KEY, message);
    }

    @Override
    public void sendMessage(String routingKey,String message) {
        rabbitTemplate.convertAndSend(DEFAULT_EXCHANGE, routingKey, message);
    }

    @Override
    public void sendMessage(ExchangeType exchange, String routingKey, String message) {
        rabbitTemplate.convertAndSend(exchange.toString(), routingKey, message);
    }
}
